<?php
use yii\helpers\Url;

$web = Url::base();
$scriptUrl = \Yii::$app->request->scriptUrl;

?>
<script src="<?= $web ?>/js/treecheck-autocomplete.js"></script>
<script type="application/javascript">

    var isRefresh = 0;
    var sendrecord = {}; //定义导入用户记录内容
    var userList = new Array(); //用户列表
    var insCode = 0;  //操作人员机构
    var insSelect2;  //主页面机构下拉
    var insSelect3;  //新增修改人员页面机构下拉
    var insSelect4;  //导入页面机构下拉
    var user_id;
    var inputDepartment; //子机构下拉
    var department = '';    //操作人员子机构
    $(function ($) {
        loading.hide();
        //操作人员机构
        insCode = "<?= $institution?>";
        department = "<?=$department?>";

        //主页面机构下拉列表内容初始化
        var institution =  <?= json_encode($institutionList) ?>;
        insSelect2 = $('#select2').treeAutocomplete({
            defaultText: '----请选择机构----',
            source: institution,
            onSelected: function (element) {
                //新增子机构选择
                var department_div = $("#department_div");
                var html = "";
                html += '<div id="inputdepartment"></div>';

                department_div.html(html);
                var institution_code = element.getValue();
                var action = "<?=$scriptUrl?>" + "/common" + "/department-tree-handler";
                var data = {};
                data.institution_code = institution_code;
                requestJson(action, data, true, function (responseData) {

                    if (responseData.status == 0 && responseData.data != '') {
                        $('#inputdepartment').treeAutocomplete({
                            defaultText: "--选择子机构(部门)--",
                            isShowCode: false,
                            source: responseData.data
                        });
                        $("#department_div").css("display", "block");
                    } else {
                        $("#department_div").css("display", "none");
                    }
                });

            }
        }).setValue("<?= $selectedInstitution ?>");

        //子机构有缺省值，则初始化树
        if (!("<?= $selectedInstitution ?>" == '' || "<?= $selectedInstitution ?>" == 0) || !(insCode == '' || insCode == '0')) {
            var department_selected = $("#department_div");
            var html_selected = "";
            html_selected += '<div id="inputdepartment"></div>';
            department_selected.html(html_selected);
            var institution_code;
            if (!("<?= $selectedInstitution ?>" == '' || "<?= $selectedInstitution ?>" == 0)) {
                institution_code = "<?=$selectedInstitution?>";
            } else if (!(insCode == '' || insCode == '0')) {
                institution_code = "<?=$institution?>";
            }
            var action = "<?=$scriptUrl?>" + "/common" + "/department-tree-handler";
            var data = {};
            data.institution_code = institution_code;
            requestJson(action, data, true, function (responseData) {
                if (responseData.status == 0 && responseData.data != '') {
                    $('#inputdepartment').treeAutocomplete({
                        defaultText: "--选择子机构(部门)--",
                        isShowCode: false,
                        source: responseData.data
                    }).setValue("<?= $selectedDepartment ?>");
                    $("#department_div").css("display", "block");
                } else {
                    $("#department_div").css("display", "none");
                }
            });
        }


        //新增修改人员页面机构下拉列表内容初始化
        insSelect3 = $('#select3').treeAutocomplete({
            defaultText: '----请选择机构----',
            source: institution,
            onSelected: function (element) {
                var department_selected = $("#userdepartment_div");
                var html_selected = "";
                html_selected += '<div id="inputdepartment_user"></div>';
                department_selected.html(html_selected);
                var institution_code = element.getValue();
                var action = "<?=$scriptUrl?>" + "/common" + "/department-tree-handler";
                var data = {};
                data.institution_code = institution_code;
                requestJson(action, data, true, function (responseData) {
                    if (responseData.status == 0 && responseData.data != '') {
                        inputDepartment = $('#inputdepartment_user').treecheckAutocomplete({
                            defaultText: "--搜索子机构(部门)--",
                            isShowCode: false,
                            source: responseData.data
                        });
                        $("#userSubIns").css("display", "block");
                    } else {
                        $("#userSubIns").css("display", "none");
                        inputDepartment = '';
                    }
                });
            }
        });

        //导入页面机构下拉列表内容初始化
        insSelect4 = $('#select4').treeAutocomplete({
            defaultText: '----请选择机构----',
            source: institution,
            onSelected: function (element) {
                //新增子机构选择
                var department_div = $("#departmentImport_div");
                var html = "";
                html += '<div id="inputdepartment_import"></div>';

                department_div.html(html);

                var institution_code = element.getValue();
                var action = "<?=$scriptUrl?>" + "/common" + "/department-tree-handler";
                var data = {};
                data.institution_code = institution_code;
                requestJson(action, data, true, function (responseData) {
                    if (responseData.status == 0 && responseData.data != '') {
                        $('#inputdepartment_import').treeAutocomplete({
                            defaultText: "--选择子机构(部门)--",
                            isShowCode: false,
                            source: responseData.data
                        });
                        $("#importSubIns").css("display", "block");
                    } else {
                        $("#importSubIns").css("display", "none");
                    }
                });

            }
        });

        //子机构管理员，导入页面，初始化子机构树
        if (!(insCode == '' || insCode == '0')) {
            var disabled = true;
            var department_selected = $("#departmentImport_div");
            var html_selected = "";
            html_selected += '<div id="inputdepartment_import"></div>';
            department_selected.html(html_selected);
            var institution_code = "<?=$institution?>";
            var action = "<?=$scriptUrl?>" + "/common" + "/department-tree-handler";
            var data = {};
            data.institution_code = institution_code;
            requestJson(action, data, true, function (responseData) {
                if (responseData.status == 0 && responseData.data != '') {
                    $('#inputdepartment_import').treeAutocomplete({
                        defaultText: "--选择子机构(部门)--",
                        isShowCode: false,
                        source: responseData.data
                    }).setValue(department);
                    $("#importSubIns").css("display", "block");
                } else {
                    $("#importSubIns").css("display", "none");
                }
            });
        }


        if (insCode != 0) {
            $("#importUserIntegral").css("display", "none");
            insSelect4.setValue(insCode);
        }


        if ("<?= $filter ?>" == 0) {
            $('#search1').val("");
        } else {
            $('#search1').val("<?= $filter ?>");
        }

        $("#select1").val("<?= $status ?>");


        //全选
        $(".table th").find(".choice-checkbox").click(function () {
            if ($(this).prop("checked")) {
                $("table tr td [type='checkbox']").prop("checked", true);
            } else {
                $("table tr td [type='checkbox']").prop("checked", false);
            }
        });


        $('#detailUser').on('show.bs.modal', function (e) {
//            alert('a');
//            $("#detail_content").html('正在加载数据....');
//            var data = {};
//            data.user_id = e.relatedTarget.attributes['data-user-id'].value;
//            requestHtml('user-summary-partview', data, true, function (responseHtml) {
//                $("#detail_content").html(responseHtml);
//            });
        });
    });

    function integralDetail(userId) {
        $("#detail_content").html('正在加载数据....');
        var data = {};
        data.user_id = userId;
        requestHtml('user-summary-partview', data, true, function (responseHtml) {
            $("#detail_content").html(responseHtml);
        });
    }

    //新增修改会员 子机构为空输入''
    function addModifyUser(institutionId, userId, departmentId) {

        $("#alert1").css("display", "none");
        $("#alert2").css("display", "none");
        $("#alert3").css("display", "none");
        $("#addUser").modal('show');
        insSelect3.setValue(institutionId);
        $("#userId").val(userId);
        var data = {};
        data.id = userId;
        if (userId == 0) {
            if (insCode == 0) {
                insSelect3.setDisabled(false);
            } else {
                insSelect3.setDisabled(true);
            }
            $("#userName").val('');
            $("#userPhone").val('');

            $("#isEnabled").prop("checked", true);

            $("#remark").val('');

        } else {
            requestJson("user-detail-handler", data, true, function (re) {
                insSelect3.setDisabled(true);
                $("#userName").val(re.data.record.name);
                $("#userPhone").val(re.data.record.phone);
                if (re.data.record.is_enabled == 1) {
                    $("#isEnabled").prop("checked", true);
                } else {
                    $("#isEnabled").prop("checked", false);
                }
                $("#remark").val(re.data.record.remark);
                $("#wx_openid").val(re.data.record.wx_openid);
                $("#header_url").val(re.data.record.header_url);
            });
        }
        var inputShow = true;
        if (department != '') {
            inputShow = false;
        }
        var department_selected = $("#userdepartment_div");
        var html_selected = "";
        html_selected += '<div id="inputdepartment_user"></div>';
        department_selected.html(html_selected);
        var institution_code = institutionId;
        var action = "<?=$scriptUrl?>" + "/common" + "/department-tree-handler";
        var data = {};
        data.institution_code = institution_code;
        requestJson(action, data, true, function (responseData) {
            if (responseData.status == 0 && responseData.data != '') {
                inputDepartment = $('#inputdepartment_user').treecheckAutocomplete({
                    defaultText: "--搜索子机构(部门)--",
                    isShowCode: false,
                    inputShow: inputShow,
                    source: responseData.data
                }).setValue(departmentId);
                $("#userSubIns").css("display", "block");
            } else {
                $("#userSubIns").css("display", "none");
                inputDepartment = '';
            }
        });
    }

    //新增修改会员确认
    function addConfirm() {
        var data = {};
        var checkPhone = /^1\d{10}$/;
        data.id = $("#userId").val();
        data.name = $("#userName").val();
        data.institution_code = $("#select3").val();
        data.phone = $("#userPhone").val();
        data.remark = $("#remark").val();
        data.wx_openid = $("#wx_openid").val();
        data.header_url = $("#header_url").val();
        if (inputDepartment == '') {
            data.department = '';
        } else {
            data.department = inputDepartment.getValue();
        }
        if ($("#isEnabled").is(':checked') == true) {
            data.isEnabled = 1;
        } else {
            data.isEnabled = 0;
        }

        if (data.institution_code == 0) {
            $("#alert3").css("display", "block");
        }
        else if (data.name == '') {
            $("#alert1").css("display", "block");
        }
        else if (data.phone == '' || !checkPhone.test(data.phone)) {
            $("#alert2").css("display", "block");
        } else {
            loading.show();
            requestJson("add-user-handler", data, true, function (re) {
                loading.hide();
                if (re.status == 0) {
                    //$("#message").text('操作成功！');
                    alert('操作成功！');
                    isRefresh = 1;
                    refresh();
                }
                else if (re.status == 9) {
                    //$("#message").text('该手机号码已被注册过！');
                    alert('该手机号码已被注册过！');
                } else {
                    //$("#message").text('操作失败！');
                    alert('操作失败！');
                }
                //$("#institutionModal3").modal('show');
                //isRefresh = data.id;

            });
        }
    }

    //变更用户启用状态
    function modifyStatus(id, isEnabled) {
        loading.show();
        var data = {};
        data.id = "'" + id + "'";
        data.isEnabled = isEnabled;
        requestJson("modify-status-handler", data, true, function (re) {
            loading.hide();
            if (re.message) {
                alert('操作失败！');
                isRefresh = 1;
                refresh();
            } else {
                alert('操作成功！');
                window.location.reload();
            }
            //$("#institutionModal3").modal('show');
            //isRefresh = 1;
            //location.reload();

        });

    }

    function modifyStatuses(isEnabled) {
        loading.show();
        var ids = "'";
        var data = {};
        data.isEnabled = isEnabled;
        $(".choice-checkbox").each(function () {
            if ($(this).is(':checked') == true) {
                if ($(this).parent().find('.hidden_id').val()) {
                    ids = ids + $(this).parent().find('.hidden_id').val() + "','";
                }
            }
        });

        data.id = ids.substr(0, ids.length - 2);
        if (data.id == "") {
            alert("请选择需要修改的项");
            loading.hide();
            return false;
        }
        requestJson("modify-status-handler", data, true, function (re) {
            loading.hide();
            if (re.message) {
                alert(re.message);
            } else {
                alert('操作成功！');
                isRefresh = 1;
                refresh();
            }
            //$("#institutionModal3").modal('show');
            //location.reload();


        });
    }

    //搜索
    function search() {
        var institutionCode = $("#select2").val();
        if (institutionCode == 0) {
            alert("请选择机构！")
        } else {
            var status = $("#select1").val();
            var filter;
            var f = $('#search1').val()._trim();
            var department_id = $("#inputdepartment").val();
            var href = window.location.href;
            var index = href.indexOf("?");
            if (index > 0) {
                href = href.substr(0, index);
            }
            href = setUrlParam(href, 'institutionCode', institutionCode);
            if (f != '') {
                href = setUrlParam(href, 'filter', f);
            }
            if (status != '1') {
                href = setUrlParam(href, 'status', status);
            }
            if (department_id != '') {
                href = setUrlParam(href, 'department_id', department_id);
            }

            window.location.href = href;
            loading.show();
        }
    }

    //会员积分变更查看
    function queryIntegral(id) {

    }

    //导入用户
    function importUser(i) {
        $("#importUserDialog").modal('show');
        $("#step1").show();
        $("#step2").hide();
        $("#step3").hide();
        //机构列表内容确认
        $(".two-error").text('');
        $("#alert4").css("display", "none");
        $("#alert5").css("display", "none");
        sendrecord.importType = i;
        if (i) {
            $("#excel-download").attr('href', "<?= $web ?>/userAdvancedemo.xlsx");
        } else {
            $("#excel-download").attr('href', "<?= $web ?>/userdemo.xlsx");
        }
    }

    //上一步下一步
    function nextStep(step) {
        sendrecord.insId = $("#select4").val();
        sendrecord.departmentId = $("#inputdepartment_import").val();

        switch (step) {

            //选择机构
            case 1:
                $("#step1").show();
                $("#step2").hide();
                break;

            //下载excel
            case 2:
                if ($("#select4").val() == 0) {
                    $("#alert4").css("display", "block");
                } else if ($("#inputdepartment_import").val() == '' && department != '') {
                    $("#alert5").css("display", "block");
                }
                else {
                    $("#step2").show();
                    $("#step1").hide();
                    $("#step3").hide();
                }
                break;


            //上传excel
            case 3:
                $("#step3").show();
                $("#step2").hide();
                $('#upload_image_submit_form').attr('action', "import-user?institutionCode=" + sendrecord.insId + "&importType=" + sendrecord.importType + "&departmentId=" + sendrecord.departmentId);
                break;

            default:
                break;

        }
    }

    //上传excel处理
    function uploadClick() {
        if ($("#upload_image").val() != '') {
            $("#upload_image_submit_form").submit();
            loading.show();
            $("#upload_exec_target").load(function () {
                try {
                    var result = eval('(' + ($("#upload_exec_target").contents().find("body").html()) + ')');
                    if (result.status == 0 && result.data.iCount > 0) {
                        text = "导入成功！导入用户：" + result.data.iCount + "人。";
                        $(".two-error").text(text);
                    }
                    else if (result.status == 2) {
                        var re = eval('(' + result.message + ')');
                        $(".two-error").text(re);
                    }
                    else if (result.status == 1) {
                        var re = eval('(' + result.message + ')');
                        text = "导入失败！【手机号码：" + re[0]["phone"] + "，姓名：" + re[0]["name"] + "】导入内容不正确：" + re[0]["error"] + "请修改后重新导入！";
                        $(".two-error").text(text);
                    }
                    else {
                        var re = "导入失败，请检查文件的正确性！";
                        $(".two-error").text(re);
                    }

                } catch (err) {
                    var re = $("#upload_exec_target").contents().find("h2").html();
                    $(".two-error").text(re);
                }
                $("#upload_image").val('');
                loading.hide();

            });
        }
    }

    //导出会员积分
    function exportUser() {
        var institutionCode = $("#select2").val();
        var data = {};
        if (institutionCode == 0) {
            alert("请选择机构！");
        } else {
            data.institutionCode = institutionCode;
            data.status = $("#select1").val();
            data.department_id = $("#inputdepartment").val();
            var f = $('#search1').val()._trim();
            if (f == '') {
                data.filter = 0;
            } else {
                data.filter = f;
            }
            var result = requestJson("export-user-list-handler", data);
            fileName = "<?= $web ?>/" + result.data;
            $("#export-excel-download").attr("href", fileName);
        }
    }

    //刷新页面
    function refresh() {
        if (isRefresh != 0) {
            location.reload();
        } else {
            var href = window.location.href;
            var index = href.indexOf("?");
            if (index > 0) {
                href = href.substr(0, index);
            }
            window.location.href = href;
        }
        isRefresh = 0;
        loading.show();
    }

    function getUserDepartment(userId) {
        //alert(userId);

    }
</script>

<div class="panel panel-default">
    <div class="panel-body">
        <div class="row container-fluid">

            <button class="btn btn-default" type="button"
                    onclick="addModifyUser('<?= $institution ?>',0,'<?= $department ?>')">
                <i
                    class="fa fa-plus"></i> 新增会员
            </button>
            <button class="btn btn-default" type="button" id="importUser" onclick="importUser(0)">
                <i
                    class="glyphicon glyphicon-upload"></i> 导入会员
            </button>

            <div class="btn btn-default" type="button" id="exportUserIntegral" onclick="exportUser()">
                <i class="glyphicon glyphicon-download-alt"></i>
                <a id="export-excel-download" href="<?= $web ?>/exportUserdemo.xlsx">导出会员积分</a>
            </div>
            <button class="btn btn-default" type="button" id="importUserIntegral" onclick="importUser(1)">
                <i class="glyphicon glyphicon-upload"></i> 导入会员积分
            </button>

        </div>
    </div>
    <div class="panel-body">
        <div class="row container-fluid">
            <div class="form-group col-lg-3">
                <div class="pull-left">
                    <div id="select2"></div>
                </div>
            </div>
            <div class="form-group col-lg-3">
                <div class="pull-left" id="department_div">
                    <div id="inputdepartment"></div>
                </div>
            </div>
            <div class="form-group col-lg-2">
                <div class="pull-right">
                    <select class="form-control m-bot15" id="select1">
                        <option value="99">所有状态</option>
                        <option value="1">启用</option>
                        <option value="0">禁用</option>
                    </select>
                </div>
            </div>
            <div class="form-group col-lg-4">
                <div class="pull-right">
                    <div class="input-group">
                        <input type="text" class="form-control" id="search1" placeholder="请输入会员名称或手机号码"
                               onkeypress="if(event.keyCode==13) {search();return false;}">
                        <span class="input-group-btn">
                            <button type="submit" class="btn btn-primary" onclick="search()"><i
                                    class="fa fa-search"></i> 搜索
                            </button>
                        </span>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<div class="panel">
    <div class="panel-body">
        <div>
            <div class="col-lg-2">
                <p>
                    <button class="btn btn-danger btn-sm" type="button" onclick="modifyStatuses(0)">
                        <span class="label label-danger">禁&nbsp;&nbsp;用</span>
                    </button>
                    <button class="btn btn-success btn-sm" type="button" onclick="modifyStatuses(1)">
                        <span class="label label-success">启&nbsp;&nbsp;用</span>
                    </button>
                </p>
            </div>
            <div class="pull-right">
                <label class="control-label">合计：<?= $total['totalnum'] ?>人，剩余积分总数：<?= $total['totalintegral'] ?></label>
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-bordered table-hover table-condensed"
                   id="institutionTable">
                <thead>
                <tr>
                    <th><input type="checkbox" class="choice-checkbox"></th>
                    <th>头像</th>
                    <th>会员编码</th>
                    <th>会员名称</th>
                    <th>所属机构</th>
                    <th>子机构(部门)</th>
                    <th>手机号码</th>
                    <th>剩余积分</th>
                    <th>备注</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <?php
                for ($i = 0; $i < count($record); $i++) {
                    ?>
                    <tr>
                        <td>
                            <input type="checkbox" class="choice-checkbox">
                            <input class="hidden_id" type="hidden" value="<?= $record[$i]['id'] ?>"/>
                        </td>
                        <td>
                            <?php
                            if ($record[$i]['header_url'] == '') {
                                $record[$i]['header_url'] = $web . "/images/mall-m/head-portrait.png";
                            }
                            ?>
                            <img src="<?= $record[$i]['header_url'] ?>" style="width: 30px;height: 30px;">
                        </td>
                        <td><?= $record[$i]['code'] ?></td>
                        <td><?= $record[$i]['name'] ?></td>
                        <td><?= $record[$i]['institution_name'] ?></td>
                        <td>
                            <a href="javascript:getUserDepartment('<?= $record[$i]['id'] ?>')">
                                <?= $record[$i]['department_name'] ?>
                            </a>
                        </td>
                        <td><?= $record[$i]['phone'] ?></td>
                        <td><?= $record[$i]['integral'] ?></td>
                        <td><?= $record[$i]['remark'] ?></td>
                        <td><?php if ($record[$i]['is_enabled'] == 1) {
                                echo '<span class="label label-success">启用</span>';
                            } else {
                                echo '<span class="label label-danger">禁用</span>';
                            } ?>
                        <td>
                            <button class="btn btn-link btn-xs" type="button"
                                    onclick="addModifyUser('<?= $record[$i]['institution_code'] ?>','<?= $record[$i]['id'] ?>','<?= $record[$i]['department_id'] ?>')">
                                修改
                            </button>
                            <button class="btn btn-link btn-xs" type="button"
                                    onclick="modifyStatus('<?= $record[$i]['id'] ?>','<?= abs($record[$i]['is_enabled'] - 1) ?>')">
                                <?php if ($record[$i]['is_enabled'] == '1') {
                                    echo '禁用';
                                } else {
                                    echo '启用';
                                } ?>
                            </button>
                            <div class="btn-group">
                                <a class="btn btn-link btn-xs" data-toggle="modal"
                                   data-user-id="<?= $record[$i]['id'] ?>"
                                   href="#detailUser" onclick="integralDetail('<?= $record[$i]['id'] ?>')">积分详情</a>
                            </div>
                        </td>
                    </tr>
                    <?php
                }
                ?>
                </tbody>
            </table>
        </div>
        <div class="pull-left">
            <?= \app\widgets\LinkPagerExt::widget(['pagination' => $pagination]) ?>
        </div>
    </div>
</div>

<!-- Modal 新增、编辑用户-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="addUser" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">添加/编辑会员</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal adminex-form">
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red">*</span>会员姓名</label>
                        <input class="hidden_id" id="wx_openid" type="hidden" value=""/>
                        <input class="hidden_id" id="header_url" type="hidden" value=""/>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="userName" placeholder="">
                            <input class="hidden_id" id="userId" type="hidden" value="0"/>
                            <label id='alert1' style="display: none;"><span style="color: red">会员姓名不允许为空</span></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">所属机构</label>
                        <div class="col-sm-9">
                            <div id="select3"></div>
                            <label id='alert3' style="display: none;"><span style="color: red">请选择一个机构</span></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red">*</span>电话</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="userPhone" placeholder="">
                            <label id='alert2' style="display: none;"><span
                                    style="color: red">手机号码不正确 或 未填写！</span></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-4 col-sm-10">
                            <label class="checkbox-inline">
                                <input type="checkbox" id="isEnabled" value="option4" checked="true"><span
                                    class="btn-clipboard popovers">是否启用</span>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">备注</label>
                        <div class="col-sm-9">
                            <textarea rows="6" class="form-control" id="remark"></textarea>
                        </div>
                    </div>
                    <div class="form-group" id="userSubIns" style="display: none">
                        <label class="col-sm-3 control-label">子机构(部门)</label>
                        <div class="col-sm-9" id="userdepartment_div">
                            <div id="inputdepartment_user"></div>

                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
                <button class="btn btn-primary" onclick="addConfirm()">保存</button>
            </div>
        </div>
    </div>
</div>

<!-- 导入用户-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="importUserDialog" class="modal fade">
    <div class="modal-dialog" id="step1" style="display:none">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">确认机构</h4>
            </div>
            <div class="modal-body modal-min-height">
                <div class="form-horizontal adminex-form">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">所属机构</label>
                        <div class="col-sm-9">
                            <div id="select4"></div>
                            <label id='alert4' style="display: none;"><span style="color: red">请选择一个机构</span></label>
                        </div>
                    </div>
                    <div class="form-group" id="importSubIns" style="display: none">
                        <label class="col-sm-3 control-label">子机构(部门)</label>
                        <div class="col-sm-9">
                            <div id="departmentImport_div">
                                <div id="inputdepartment_import"></div>
                            </div>
                            <label id='alert5' style="display: none;"><span style="color: red">请选择一个子机构(部门)</span></label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
                <button class="btn btn-primary" onclick="nextStep(2)">下一步</button>
            </div>
        </div>
    </div>
    <div class="modal-dialog" id="step2" style="display:none">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">下载excel</h4>
            </div>
            <div class="modal-body">

                <div class="form-group">
                    <a id="excel-download" href="<?= $web ?>/userdemo.xlsx">
                        <img src="<?= $web ?>/images/hair-two-1.png">【点我】下载excel模板
                    </a>
                </div>

            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
                <button class="btn btn-default" onclick="nextStep(1)">上一步</button>
                <button class="btn btn-primary" onclick="nextStep(3)">下一步</button>
            </div>
        </div>
    </div>
    <div class="modal-dialog" id="step3" style="display:none">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">上传excel</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <div class="two-center">
                        <div class="two-words two-error-none">请点击【选择文件】导入EXCEL!<span
                                style="color: red">注意：每次导入记录数不能超过5000条！</span>导入的时间可能很长，请耐心等待！
                        </div>
                        <div class="two-error" style="color: red"></div>
                    </div>
                </div>
                <div class="form-group">
                    <form id="upload_image_submit_form" enctype="multipart/form-data" method="post"
                          action="import-user" target="upload_exec_target">
                        <input id="upload_image" name="file" type="file" onchange="uploadClick()"/>
                        <input type="hidden" name="dir"/>
                        <img src="<?= $web ?>/images/hair-two-1.png">
                    </form>
                    <iframe id="upload_exec_target" name="upload_exec_target" style="display: none;"></iframe>
                </div>

            </div>
            <div class="modal-footer">
                <button class="btn btn-default" onclick="nextStep(2)">上一步</button>
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 提示框 -->
<div aria-hidden="true" role="dialog" tabindex="-1" id="institutionModal3" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">消息</h4>
            </div>
            <div class="modal-body" id="message">

                操作失败！

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" onclick="refresh()"> Ok</button>
            </div>
        </div>
    </div>
</div>


<!--会员详情-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="detailUser" class="modal fade">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">会员积分详情</h4>
            </div>
            <div class="modal-body" id="detail_content">
                正在加载数据....
            </div>
        </div>
    </div>
</div>
